/*****************************************************************************
 * Copyright (C) Stacy Curl. All rights reserved.                            *
 * ------------------------------------------------------------------------- *
 * The software in this package is published under the terms of the BSD      *
 * style license a copy of which has been included with this distribution in *
 * the LICENSE.txt file.                                                     *
 *****************************************************************************/
package picounit.features.test_finder;

import picounit.Marker;
import picounit.util.Equal;
import picounit.verify.constraint.EqualUtil;
import junit.framework.TestCase;
import junit.framework.TestResult;

class NoTestsFoundTestCase extends TestCase implements Equal<NoTestsFoundTestCase>{
	private final Marker marker;

	public NoTestsFoundTestCase(Class<?> startingClass, Marker marker) {
		super(startingClass.getName());

		this.marker = marker;
	}

	public boolean matches(String name, Marker marker) {
		return getName().equals(name) &&
			this.marker.equals(marker);
	}

	@Override
	public void run(TestResult testResult) {
		testResult.startTest(this);

		testResult.addError(this, new NoTestsFoundException(marker));

		testResult.endTest(this);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Equal methods
	///////////////////////////////////////////////////////////////////////////////////////////////
	
	public boolean equalTo(NoTestsFoundTestCase other) {
		return other.matches(getName(), marker);
	}
	
	///////////////////////////////////////////////////////////////////////////////////////////////
	// Object methods
	///////////////////////////////////////////////////////////////////////////////////////////////

	@Override
	public boolean equals(Object object) {
		return EqualUtil.isEqual(this, object);
	}

	@Override
	public int hashCode() {
		return marker.hashCode();
	}
}